(function(){
	var c=YAHOO.util.Dom,e=YAHOO.util.Event;
	YAHOO.namespace("ChatXP.ui");

	var chatWin;
     
	YAHOO.ChatXP.ui.MainPanel = function(f) {
		var X=this._id_pre+"face_panel";

		var ab=document.createElement("DIV");
		ab.id=X;
		ab.style.display="none";
		ab.className="face";
		ab.innerHTML='<div class="faceBg"><div class="faceImg"><a title="[/:)]" id="face_0" ></a><a title="[/:~]" id="face_1"></a><a title="[/:B]" id="face_2"></a><a title="[/:|]" id="face_3"></a><a title="[/8-)]" id="face_4"></a><a title="[/:<]" id="face_5"></a><a title="[/:$]" id="face_6"></a><a title="[/:X]" id="face_7"></a><a title="[/:Z]" id="face_8"></a><a title="[/:\'(]" id="face_9"></a><a title="[/:-|]" id="face_10"></a><a title="[/:@]" id="face_11"></a><a title="[/:P]" id="face_12"></a><a title="[/:D]" id="face_13"></a><a title="[/:O]" id="face_14"></a><a title="[/:(]" id="face_15"></a><a title="[/:+]" id="face_16"></a><a title="[/--b]" id="face_17"></a><a title="[/:Q]" id="face_18"></a><a title="[/:T]" id="face_19"></a><a title="[/;P]" id="face_20"></a><a title="[/;-D]" id="face_21"></a><a title="[/;d]" id="face_22"></a><a title="[/;o]" id="face_23"></a><a title="[/:g]" id="face_24"></a><a title="[/|-)]" id="face_25"></a><a title="[/:!]" id="face_26"></a><a title="[/:L]" id="face_27"></a><a title="[/:>]" id="face_28"></a><a title="[/:;]" id="face_29"></a><a title="[/;f]" id="face_30"></a><a title="[/:-S]" id="face_31"></a><a title="[/?]" id="face_32"></a><a title="[/;x]" id="face_33"></a><a title="[/;@]" id="face_34"></a><a title="[/:8]" id="face_35"></a><a title="[/;!]" id="face_36"></a><a title="[/!!!]" id="face_37"></a><a title="[/xx]" id="face_38"></a><a title="[/bye]" id="face_39"></a><a title="[/wipe]" id="face_40"></a><a title="[/dig]" id="face_41"></a><a title="[/handclap]" id="face_42"></a><a title="[/&-(]" id="face_43"></a><a title="[/B-)]" id="face_44"></a><a title="[/<@]" id="face_45"></a><a title="[/@>]" id="face_46"></a><a title="[/:-O]" id="face_47"></a><a title="[/>-|]" id="face_48"></a><a title="[/P-(]" id="face_49"></a><a title="[/:\'|]" id="face_50"></a><a title="[/X-)]" id="face_51"></a><a title="[/:*]" id="face_52"></a><a title="[/@x]" id="face_53"></a><a title="[/8*]" id="face_54"></a><a title="[/pd]" id="face_55"></a><a title="[/<W>]" id="face_56"></a><a title="[/beer]" id="face_57"></a><a title="[/basketb]" id="face_58"></a><a title="[/oo]" id="face_59"></a><a title="[/coffee]" id="face_60"></a><a title="[/eat]" id="face_61"></a><a title="[/pig]" id="face_62"></a><a title="[/rose]" id="face_63"></a><a title="[/fade]" id="face_64"></a><a title="[/showlove]" id="face_65"></a><a title="[/heart]" id="face_66"></a><a title="[/break]" id="face_67"></a><a title="[/cake]" id="face_68"></a><a title="[/li]" id="face_69"></a><a title="[/bome]" id="face_70"></a><a title="[/kn]" id="face_71"></a><a title="[/footb]" id="face_72"></a><a title="[/ladybug]" id="face_73"></a><a title="[/shit]" id="face_74"></a><a title="[/moon]" id="face_75"></a><a title="[/sun]" id="face_76"></a><a title="[/gift]" id="face_77"></a><a title="[/hug]" id="face_78"></a><a title="[/strong]" id="face_79"></a><a title="[/weak]" id="face_80"></a><a title="[/share]" id="face_81"></a><a title="[/v]" id="face_82"></a><a title="[/@)]" id="face_83"></a><a title="[/jj]" id="face_84"></a><a title="[/@@]" id="face_85"></a><a title="[/bad]" id="face_86"></a><a title="[/loveu]" id="face_87"></a><a title="[/no]" id="face_88"></a><a title="[/ok]" id="face_89"></a><a title="[/love]" id="face_90"></a><a title="[/<L>]" id="face_91"></a><a title="[/jump]" id="face_92"></a><a title="[/shake]" id="face_93"></a><a title="[/<O>]" id="face_94"></a><a title="[/circle]" id="face_95"></a><a title="[/kotow]" id="face_96"></a><a title="[/turn]" id="face_97"></a><a title="[/skip]" id="face_98"></a><a title="[/oY]" id="face_99"></a><a title="[/#-O]" id="face_100"></a><a title="[/hiphop]" id="face_101"></a><a title="[/kiss]" id="face_102"></a><a title="[/<&]" id="face_103"></a><a title="[/&>]" id="face_104"></a></div></div>';
		document.body.appendChild(ab);
		this._face_panel_ref = ab;
		
		for(var ak=0;ak<105;ak++){
			var j=c.get("face_"+ak);
			e.on(j,"mousedown",this.mf_InsertFace,this,true)
		}
		
		
		//this._tabsManager = new YAHOO.ChatXP.ui.TabsManager(this, {});
		
		YAHOO.log("end MainPanel ctr");
	};
	
	//传入发送消息的窗口对象，否则底层不知道上层发送的窗口对象
	
	YAHOO.ChatXP.ui.MainPanel.getInstance = function(o){
		if(!YAHOO.ChatXP.ui.MainPanel.prototype.instance){
			YAHOO.ChatXP.ui.MainPanel.prototype.instance=new YAHOO.ChatXP.ui.MainPanel("mainwindow")
			chatWin = o;
		}
		return YAHOO.ChatXP.ui.MainPanel.prototype.instance;
	};

	YAHOO.ChatXP.ui.MainPanel.prototype = {
			mf_ReceiveClassMsg:function(msgs) {
				if(chatWin === undefined) {
					chatWin = new YAHOO.ChatXP.ui.ChatWin("q");
				}
				
				
				chatWin.mf_notify_recv(msgs);
				YAHOO.log("after chatWin.mf_notify_recv", "info");
			},
			mf_ShowFace:function(g) {
				var f = e.getTarget(e.getEvent(g));
				/*var i=c.getX(f)-2;
				var h=c.getY(f)-220;
				*/
				var i=c.getX(f)+50;
				var h=c.getY(f)+100;
				this._face_panel_ref.style.left=i+"px";
				this._face_panel_ref.style.top=h+"px";
				this._face_panel_ref.style.display="block";
				e.on(window.document,"mousedown",this.mf_FaceHide,this,true);
				e.stopEvent(g)
			},
			mf_FaceHide:function(){
				this._face_panel_ref.style.display="none";
				e.removeListener(window.document,"mousedown",this.mf_FaceHide)
			},
			mf_InsertFace:function(j){
				e.stopEvent(j);
				var h = e.getTarget(e.getEvent(j));
				this.mf_FaceHide();
				var i=parseInt(h.id.substr(h.id.search("face_")+String("face_").length));
				var g=document.createElement("IMG");g.setAttribute("align","absmiddle");
				g.src="images/emotions/"+i+".gif";

				var input = chatWin._input_ref.firstChild;
				input.focus();
				
				if(e.isIE){
					this._addIEFace(input,h.title)
				}else{
					this._addNotIEFace(input,h.title)
				}
				//alert(chatWin._input_ref);
				chatWin._input_ref.firstChild.focus()
			},
			_addIEFace:function(f,j){
				var g=document.selection;
				if(g&&g.createRange){
					var h=g.createRange();
					h.text=j;
					try{
						h.moveStart("character",-strlen(j))
					}catch(i){}
				}else{f.value+=j}
			},
			_addNotIEFace:function(f,h){
				var g=document.selection;
				if(!(typeof f.selectionStart=="undefined")){
					f.value=f.value.substr(0,f.selectionStart)+h+f.value.substr(f.selectionEnd);
				}else{
					f.value+=h;
				}
			}
	};
	
})()